import React from 'react';
import {HashRouter as Router,Link,withRouter} from "react-router-dom";
import "./Login.css"
import "../../config.js"
import axios from "axios"

class MyCom extends React.Component{
	constructor(props){
		super(props);
		document.cookie="phoneNum=null";
	}

	Login(){
		var getPhoneNum=this.phoneNum.value;
		var getPass=this.pass.value;
		if(getPhoneNum===''){
			alert("账号不能为空！");
			return;
		}else if(getPass===''){
			alert("密码不能为空!");
			return;
		}
		axios.get(global.routes.database+'/Login',{
			params:{
				phoneNum:getPhoneNum,
				pass:getPass
			}
		}).then((res)=>{
			console.log(res.data.code);
			if(res.data.code===200){
				document.cookie="phoneNum="+getPhoneNum;
				this.props.history.push('/terran/myAfterLogin')
			}else{
				alert("账号或密码错误！");
			}
		})
	}

	render(){
		return(
			<div className="div-Login">
				<div className="div-Head">
					<Router>
                        <Link to='/terran/my'><img src={require("./back.png")} width="10%" height="40px" className="login-img" alt="返回"/></Link>
                    </Router>
					<p className="login-p-len">基金交易安全登录</p>
				</div>
				<div className="div-Input">
					<p className="login-p">手机号：</p>
					<input className="login-input" type="text" placeholder="请输入手机号" ref={input=>this.phoneNum=input}/>
				</div>
				<div className="div-Input">
					<p className="login-p">密码：</p>
					<input className="login-input" type="password" placeholder="请输入登录密码" ref={input=>this.pass=input}/>
				</div>
				<div className="div-Button">
					<button className="login-button" onClick={this.Login.bind(this)}>安 全 登 录</button>
					<br />
					<Router>
                        <Link to='/terran/register'>
                        	<button className="button2">没有基金账户，10秒开户</button>
                        </Link>
                    </Router>
				</div>
			</div>
		)
	}
}

export default withRouter(MyCom)